//
//  CGContactViewController.m
//  SchoolClient
//
//  Created by mac on 15/11/3.
//  Copyright © 2015年 mac. All rights reserved.
//

#import "CGContactViewController.h"
#import "CGUser.h"

@interface CGContactViewController ()

@property(nonatomic,strong)NSArray *titles;
@property(nonatomic,strong)NSMutableArray *contents;
@property(nonatomic,strong)NSMutableArray *labels;

@end

@implementation CGContactViewController

-(NSArray *)titles{
    if (!_titles) {
        _titles = @[@"公司",@"电话",@"邮箱",@"QQ",@"地址"];
    }
    return _titles;
}

-(NSMutableArray *)contents{
    if (!_contents) {
        _contents = [NSMutableArray array];
    }
    return _contents;
}

-(NSMutableArray *)labels{
    if (!_labels) {
        _labels = [NSMutableArray array];
    }
    return _labels;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [Tools getColor:@"ebebeb"];
    self.title = @"联系我们";
    
     [self fetchContactInfo];
    
     [self layoutUI];
}

-(void)layoutUI{
    for (int i = 0; i < self.titles.count; i ++) {
        
        CGRect aFrame = CGRectMake(0, 15 + 45*i, SCREEN_WIDTH, 44);
        UIView *containView = [[UIView alloc]initWithFrame:aFrame];
        containView.backgroundColor = [UIColor whiteColor];
        [self.view addSubview:containView];
        //标题
        CGRect bFrame = CGRectMake(10,15 + 45*i, 60, 44);
        UILabel *titleLabel = [[UILabel alloc]initWithFrame:bFrame];
        titleLabel.text = self.titles[i];
        [self.view addSubview:titleLabel];
        
        //内容
        CGRect cFrame = CGRectMake(60,15 + 45*i, SCREEN_WIDTH - 60 - 10, 44);
        UILabel *contentLabel = [[UILabel alloc]initWithFrame:cFrame];
        contentLabel.textColor = [UIColor darkGrayColor];
        contentLabel.tag = i;
        [self.labels addObject:contentLabel];
        [self.view addSubview:contentLabel];
        
    }
}

-(void)fetchContactInfo{

    //发送请求
    CGAccountDefault *user = [CGAccountDefault shareAccount];
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    parameters[@"id"] = user.user_id;
    ZYHRequest *request = [ZYHRequest new];
    
    
    [request postAsyncEncryptRequest:@"/main/getInfoAdmin.app" parameters:parameters success:^(id responseData) {
        
        CGUser *user = [CGUser objectWithJSONData:responseData];
        [self.contents addObject:user.companyName];
        [self.contents addObject:user.tphone];
        [self.contents addObject:user.mail];
        [self.contents addObject:user.qq];
        [self.contents addObject:user.loaction];
        
        for (int i = 0; i < self.labels.count; i ++) {
            UILabel *label = self.labels[i];
            label.text = self.contents[i];
        }

    } failure:^(NSError *error) {
        NSLog(@"%@",error);
    }];
    
}


@end
